<template>
  <div>
    <div
      v-for="(item, index) in arr"
      :key="index"
      style="display: inline-block"
    >
      <input type="checkbox" v-model="userNum" :value="item" />
      <span>{{ item }}</span>
    </div>

    <div>你选中的元素累加和为:&nbsp;&nbsp;{{ addNum }}</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: [9, 15, 19, 25, 29, 31, 48, 57, 62, 79, 87],
      userNum: [],
    };
  },
  computed: {
    addNum() {
      //reduce 方法 数组方法复习  bilibii
      return this.userNum.reduce((sum, val) => {
        return (sum += val);
      }, 0);
    },
  },
};
</script>

<style>
</style>